package com.link2room.optimus.nmsrunner;

import com.aliyun.mns.model.Message;
import com.link2room.common.mns.Worker;
import com.link2room.common.util.JacksonUtil;
import com.link2room.optimus.facade.IMarketingFacadeService;
import com.link2room.jetfire.dto.param.base.ReservationParamDto;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by sss on 2016/9/21.
 */
@Component("marketingChangeStockRunner")
public class MarketingChangeStockRunnerImpl implements Worker {
    @Resource
    private IMarketingFacadeService marketingFacadeService;

    @Override
    public boolean exec(Message message) throws Exception {
        try{
            ReservationParamDto reservationParamDto = JacksonUtil.jsonToBean(message.getMessageBody(), ReservationParamDto.class);
            if(message.getDequeueCount()==1){
                marketingFacadeService.changeMarketingStock(reservationParamDto);
            }
        }catch (Exception e){
            throw new RuntimeException();
        }finally {
            return true;

        }
    }
}
